package com.fyzk.activity.lottery.zc.tz_dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.activity.lottery.jc.football.JCInfo;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

public class ZCBF_Dialog_zjq extends ZC_Dialog_BaseActivity {


    // 中间
    private View view;

    private LinearLayout ll_xxk;

    private GridView gr;
    private ZCZJQ_DLG_GR_adapter adapter;
    private List<ZCBF_infor> list_zjq = new ArrayList<ZCBF_infor>();


    private String[] keyArray = null;

    public ZCBF_Dialog_zjq(Context context, JCInfo infos) {
        super(context, infos);
        init();
    }

    @Override
    protected void init() {
        addBiFen();
        info();

        keyArray = new String[]{
                infor.SCORE_0, infor.SCORE_1, infor.SCORE_2, infor.SCORE_3,
                infor.SCORE_4, infor.SCORE_5, infor.SCORE_6, infor.SCORE_7};
    }

    @Override
    public void sureClick() {
        super.sureClick();
        int clickNum = 0;
        for (ZCBF_infor info : list_zjq) {
            int position = list_zjq.indexOf(info);
            if (info.isSelect()) {
                clickNum++;
            }
            infor.btnHGPojo.get(keyArray[position]).isSel = info.isSelect();
        }
        infor.setOnclikNum(clickNum);
        infor.setResult(getResult(infor));

    }

    @Override
    protected JCInfo getResult() {
        return infor;
    }

    private void info() {

        view = LayoutInflater.from(context).inflate(R.layout.zc_dialog_bf, null);

        // 中间
        ll_xxk = view.findViewById(R.id.zcbf_dialog_xxk);
        gr = view.findViewById(R.id.zcbf_dlg_gr);
        adapter = new ZCZJQ_DLG_GR_adapter(list_zjq);
        ll_xxk.setVisibility(View.GONE);
        center_ll.addView(view);
        // 事件
        gr.setAdapter(adapter);

    }

    /**
     * 添加比分集合
     */
    private void addBiFen() {
        list_zjq.clear();
        for (int i = 0; i < infor.getTouZhuInfor().size(); i++) {
            if (i >= 37 && i <= 44) {// 胜
                list_zjq.add(infor.getTouZhuInfor().get(i));
            }
        }
    }

    /**
     * 适配器
     *
     * @author Administrator
     */
    class ZCZJQ_DLG_GR_adapter extends BaseAdapter {

        public List<ZCBF_infor> list = new ArrayList<ZCBF_infor>();

        public ZCZJQ_DLG_GR_adapter(List<ZCBF_infor> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(final int position, View view, ViewGroup parent) {
            view = LayoutInflater.from(context).inflate(
                    R.layout.zc_dialog_bf_gr, null);
            final ViewHolder holder = new ViewHolder();

            holder.ll1 = (LinearLayout) view.findViewById(R.id.zcbf_dlg_gr_ll1);
            holder.tv1 = (TextView) view.findViewById(R.id.zcbf_dlg_gr_tv1);
            holder.tv2 = (TextView) view.findViewById(R.id.zcbf_dlg_gr_tv2);

            view.setTag(holder);

            holder.tv1.setText(list.get(position).getBiFen());
            holder.tv2.setText(list.get(position).getPeilv());

            if (!list.get(position).isSelect()) {
                holder.tv1.setTextColor(Color.BLACK);
                holder.tv2.setTextColor(Color.BLACK);
                holder.ll1.setBackgroundResource(R.drawable.zcbf_gr_click);
            } else {
                holder.tv1.setTextColor(Color.RED);
                holder.tv2.setTextColor(Color.RED);
                holder.ll1.setBackgroundResource(R.drawable.zcbf_gr_click2);
            }

            holder.ll1.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {

                    list.get(position)
                            .setSelect(!list.get(position).isSelect());
                    if (!list.get(position).isSelect()) {
                        holder.tv1.setTextColor(Color.BLACK);
                        holder.tv2.setTextColor(Color.BLACK);
                        holder.ll1
                                .setBackgroundResource(R.drawable.zcbf_gr_click);
                    } else {
                        holder.tv1.setTextColor(Color.RED);
                        holder.tv2.setTextColor(Color.RED);
                        holder.ll1
                                .setBackgroundResource(R.drawable.zcbf_gr_click2);
                    }
                }
            });

            return view;
        }

        public List<ZCBF_infor> getList() {
            return list;
        }

        public void setList(List<ZCBF_infor> list) {
            this.list = list;
            this.notifyDataSetChanged();
        }

        @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
        }

        class ViewHolder {
            LinearLayout ll1;
            TextView tv1;
            TextView tv2;
        }

    }


}
